package com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.repository;

import java.util.ArrayList;
import java.util.List;

import com.iwhalecloud.citybrain.flow.platform.manager.application.common.event.ProcessInstanceStartEvent;
import com.iwhalecloud.citybrain.flow.platform.manager.application.service.ProcessInstanceStartHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

/**
 * @author lilh
 * @date 2019-05-05 14:38
 */
@Service
public class ProcessInstanceStartEventHandler {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private List<ProcessInstanceStartHandler> handlers = new ArrayList<>();

    @EventListener
    public void handleProcessInstanceStartEvent(ProcessInstanceStartEvent event) {

        for (ProcessInstanceStartHandler handler : handlers) {
            try {
                handler.handle(event);
            } catch (Throwable t) {
                logger.error("处理出错：{}", t.getLocalizedMessage());
            }
        }

    }


}
